use actix_web::{App, HttpServer};
use crate::{config::{HTML_DIR, WEB_SERVER_ADDR}, error::IoErr};
use actix_files as fs;

mod api;
mod resp;
mod req;
mod error;

pub async fn web_server_run() -> Result<(), IoErr> {

    println!("web server:{}", WEB_SERVER_ADDR);

    let app = || {
        let file_service = fs::Files::new("/web", HTML_DIR)
            .index_file("index.html");

        App::new()
            .service(file_service)
            .configure(api::register)
    };

    HttpServer::new(app)
        .bind(WEB_SERVER_ADDR)?
        .run()
        .await?;

    Ok(())
}

